# 函数

# 1、求1-100的和
# sum=0
# for i in range(1,101):
#     sum+=i
# print(sum)
# print("==============")
# #2、计算300-400的和
# sum=0
# for i in range(300,401):
#     sum+=i
# print(sum)
# print("==============")
# #3、计算1-1000的和
# sum=0
# for i in range(1,1001):
#     sum+=i
# print(sum)


#求数列 的和, 使用函数
# def calcSum(beg,end):
#     sum=0
#     for i in range(beg,end+1):
#         sum+=i
#     print(sum)
#
#
# calcSum(1,100)
# calcSum(2,200)
# calcSum(1,1000)


# def test1():
#     print('hello')
# #光是定义函数，而不调用则不会执行
# #函数必须先定义再使用
# test1()
#
# def calcSum(beg,end):
#     sum=0
#     for i in range(beg,end+1):
#         sum+=i
#     print(sum)
#
#
# calcSum(1,100)
# calcSum(2,200)
# calcSum(1,1000)


# def test(a,b,c):
#     print(a,b,c)
#
# test(10,1,1)

# def t(a):
#     print(a)
#
# t(1)
# t('hello')
# t(True)


# def calcSum(beg,end):
#     sum=0
#     for i in range(beg,end+1):
#         sum+=i
#     return sum
#
# a=calcSum(1,10)
# print(a)


# # 判断是否是奇数
# def isOdd(num):
#     if num%2==1:
#         return True
#     else:
#         return False
# a=isOdd(3)
# print(a)

# 判断是否是奇数
# def isOdd(num):
#     if num%2==1:
#         return True
#     return False
# a=isOdd(3)
# print(a)


#一个函数可以一次返回多个返回值的，使用，来分割
# def getPoint():
#     x=10
#     y=20
#     return x,y
#
# a,b=getPoint()
# print(a)
# print(b)
# print("=========")
# _,c=getPoint()
# print(c)

#变量作用域
# def getPoint():
#     x=1
#     y=2
#     return x,y
#
# x,y=getPoint()
# print(x,y)


# def getPoint():
#     x=1
#     y=2
#     return x,y
#
# getPoint()
# print(x,y)

# x=20
# def test():
#     x=10
#     print(f'函数内部x={x}')  # 10
# test()
# print(f'函数外部x={x}') # 20


# x=20
# def test():
#     print(f'函数内部x={x}')  # 20
# test()
# print(f'函数外部x={x}')  # 20


# x=20
# def test():
#     #如果是想在函数内部, 修改全局变量的值, 需要使用 global 关键字声明
#     global x
#     x=10
#     print(f'函数内部x={x}')  # 10
# test()
# print(f'函数外部x={x}')  # 10


# if / while / for 等语句块不会影响到变量作用域
# 换而言之, 在 if / while / for 中定义的变量, 在语句外面也可以正常使用.

# for i in range(1,10):
#     print(f'函数内部i={i}')
#
# print(f'函数外部i={i}')


# def test():
#     print("执行函数内部代码")
#     print("执行函数内部代码")
#     print("执行函数内部代码")
#
# print("hahahhahhah111")
# test()
# print("hahahhahhah22")
# test()
# print("hahahhahhah3")

#链式调用
#判断是否是奇数
# def isOdd(num):
#     if num%2==1:
#         return True
#     else:
#         return False
#
# result=isOdd(10)
# print(result)
# print("==================")
# print(isOdd(10))

# def a():
#     print("函数a")
#
# def b():
#     print("函数b")
#     a()
#
# def c():
#     print("函数c")
#     b()
#
# def d():
#     print("函数d")
#     c()
#
# d()


# def a():
#     print("函数a")
#
# def b():
#     a()
#     print("函数b")
#
#
# def c():
#     b()
#     print("函数c")
#
# def d():
#     c()
#     print("函数d")
# d()


# def factor(n):
#     if n==1:
#         return 1
#     return n*factor(n-1)
# print(factor(5))

# def add(x,y,debug=False):
#     if debug:
#         print(f'调试信息：x={x},y={y}')
#     return x+y
#
# print(add(1,2))
# print(add(1,20))


# def add(x,debug=False,y):
#     if debug:
#         print(f'调试信息：x={x},y={y}')
#     return x+y
#
# print(add(1,2))
# print(add(1,20))


#关键字参数
# def test(x,y):
#     print(f'x={x}')
#     print(f'y={y}')
#
# test(10,20)
# print("=========")
# test(x=10,y=20)
# print("=========")
# test(y=20,x=10)


